function maybe_make_diffmap () {
    local stem="$1"
    local name="$2"
    local epsilon="$3"
    local points="$4"
    local k="$5"
    local normalize="$6"
    local start_time="$7"
    # Not sure how CPUWeight and CPUQuota work, given that this reaches
    # 100% usage on my system, but at least the system doesn't hang anymore.
    local to="$name(k=$k,eps=$epsilon,points=$points,$normalize,start-time=${start_time}).diffmap"
    if [ ! -f "$to" ]
    then
	echo "computing: $to"
	# TODO: How does CPUQuota work?  1%, 400%, ???
	# TODO: make this non-systemd-specific, avoid sudo
	if sudo -E env PATH=$PATH systemd-run --scope -p MemoryAccounting=yes -p CPUAccounting=true -p MemorySwapMax=20M -p MemoryMax=6G -p CPUWeight=10 --uid=$USER --gid=$USER timeout 40s python3 construct-diffusion-map.py "$stem" "$to.tmp" "--points=$points" -k "$k" "--eps=$epsilon" "$normalize" --start-time "${start_time}";
	then
	    mv "$to.tmp" "$to" && echo "done!"
	else
	    echo "$? oops, timeout or OOM?"
	    exit 1
	fi
    else
	echo "already exists: $to, not recomputing"
    fi
}

# # Opgelet: kan traag zijn!!
# #
# #  0.01 en 0.001 duren erg lang voor BOFC
# #  Voor BOFC geen 100 nodig.
# for eps in 40 10 1 0.1;
# do
#     for points in 1000 2000 5000; # 7000; 7000 too expensive, always fails due to timeout
#     do
# 	for k in 64 512 "$points";
# 	do
# 	    #if [ "$k" -eq "7000" ]; then
# 	    #	k=2000 # 7000 is too expensive to finish in a reasonable amount of time
# 	    #fi
# 	    #   if [ "$k" -eq "5000" ]; then
# 	    #	k=2000 # 7000 is too expensive to finish in a reasonable amount of time (with some exceptions)
# 	    #   fi
# 	    for normalize in --normalize --no-normalize;
# 	    do
# 		maybe_make_diffmap results_9010/PDL_9010 BOFC "$eps" "$points" "$k" "$normalize" 25
# 	    done
# 	done
#    done
# done
# #Grrr



#maybe_make_diffmap results_9010/PDL_9010 BOFC "0.01" "5000" 64 --no-normalize 10
#python3 plot-diffusion-map.py --fit 300000 --ith-stem results_9010/PDL_9010  --interactive 'BOFC(k=64,eps=0.01,points=5000,--no-normalize,start-time=10).diffmap' BOFC "transformed scatterplot"
#python3 plot-diffusion-map.py 'BOFC(k=64,eps=0.01,points=5000,--no-normalize,start-time=10).diffmap' BOFC "correlation plots"


#maybe_make_diffmap results_9010/PDL_9010 BOFC "0.01" "5000" 64 --no-normalize 22
#python3 plot-diffusion-map.py --fit 300000 --ith-stem results_9010/PDL_9010  --interactive 'BOFC(k=64,eps=0.01,points=5000,--no-normalize,start-time=22).diffmap' BOFC "transformed scatterplot"
#python3 plot-diffusion-map.py --fit 300000 --ith-stem results_9010/PDL_9010  --interactive BOFC\(k=64,eps=0.01,p



maybe_make_diffmap results_9010/PDL_9010 BOFC "0.01" "5000" 32 --no-normalize 10
#python3 plot-diffusion-map.py --fit 300000 --ith-stem results_9010/PDL_9010  --interactive 'BOFC(k=64,eps=0.01,points=5000,--no-normalize,start-time=10).diffmap' BOFC "transformed scatterplot"
python3 plot-diffusion-map.py 'BOFC(k=32,eps=0.01,points=5000,--no-normalize,start-time=10).diffmap' BOFC "transformed scatterplot"
python3 plot-diffusion-map.py 'BOFC(k=32,eps=0.01,points=5000,--no-normalize,start-time=10).diffmap' BOFC "eigenvalues"

# Maximal number of points:   45079875
# Success: 2
#sudo -E env PATH=$PATH systemd-run --scope -p MemoryAccounting=yes -p CPUAccounting=true -p MemorySwapMax=20M -p MemoryMax=4.8G -p CPUWeight=10 --uid=$USER --gid=$USER python3 plot-diffusion-map.py --ith-stem results_9010/PDL_9010 --fit 2000000 'BOFC(k=32,eps=0.01,points=5000,--no-normalize,start-time=10).diffmap' BOFC "transformed scatterplot"


python3 plot-diffusion-map.py --axes 'BOFC(k=32,eps=0.01,points=5000,--no-normalize,start-time=10).diffmap' BOFC "correlation plots"

#python3 plot-diffusion-map.py 'BOFC(k=32,eps=0.01,points=5000,--no-normalize,start-time=10).diffmap' BOFC --ith-stem results_9010/PDL_9010 --fit 5000 "transformed scatterplot"


# Courtemanche.  To avoid file name length limits on some systems,
# Courtemanche2D is abbreviated to CM.
maybe_make_diffmap myokit12/myokit_2 'CM-nospiral' 400 6000 6000 --normalize 22 # ?? all eigenvalues are approx -0.0025
maybe_make_diffmap myokit_CMspiral3/myokit_5 'CM-spiral' 400 6000 6000 --normalize 27 # ??? 

python3 plot-diffusion-map.py 'CM-nospiral(k=6000,eps=400,points=6000,--normalize,start-time=22).diffmap' CM-nospiral "transformed scatterplot"
python3 plot-diffusion-map.py 'CM-spiral(k=6000,eps=400,points=6000,--normalize,start-time=27).diffmap' CM-spiral "transformed scatterplot"

python3 plot-diffusion-map.py 'CM-nospiral(k=6000,eps=400,points=6000,--normalize,start-time=22).diffmap' CM-nospiral "correlation plots"
python3 plot-diffusion-map.py 'CM-nospiral(k=6000,eps=400,points=6000,--normalize,start-time=22).diffmap' CM-nospiral "eigenvalues"
python3 plot-diffusion-map.py 'CM-spiral(k=6000,eps=400,points=6000,--normalize,start-time=27).diffmap' CM-spiral "eigenvalues"

# Transformed phaseplot
#sudo -E env PATH=$PATH systemd-run --scope -p MemoryAccounting=yes -p CPUAccounting=true -p MemorySwapMax=20M -p MemoryMax=2.4G -p CPUWeight=10 --uid=$USER --gid=$USER python3 plot-diffusion-map.py  --ith-stem myokit12/myokit_2 --fit 10000 'Courtemanche2D-nospiral(k=6000,eps=400,points=6000,--normalize,start-time=22).diffmap' Courtemanche2D-nospiral "transformed scatterplot"


#python3 plot-diffusion-map.py 'Courtemanche2D-nospiral(k=6000,eps=400,points=6000,--normalize,start-time=22).diffmap' Courtemanche2D-nospiral "correlation plots"


# AP model
#  0.04 werkt
#  0.03 werkt (wel trager)
e=0.02
maybe_make_diffmap phase_1000/phase_1000 'AP' "$e" 100 100 --no-normalize 2
maybe_make_diffmap phase_1000/phase_1000 'AP' "$e" 200 200 --no-normalize 2
maybe_make_diffmap phase_1000/phase_1000 'AP' "$e" 1000 1000 --no-normalize 2
maybe_make_diffmap phase_1000/phase_1000 'AP' "$e" 3000 3000 --no-normalize 2
maybe_make_diffmap phase_1000/phase_1000 'AP' "$e" 5000 5000 --no-normalize 2
maybe_make_diffmap phase_1000/phase_1000 'AP' "$e" 6000 6000 --no-normalize 2
#maybe_make_diffmap phase_1000/phase_1000 'AP' "$e" 7000 7000 --no-normalize 2

# Plots for AP model
python3 plot-diffusion-map.py "AP(k=6000,eps=$e,points=6000,--no-normalize,start-time=2).diffmap" AP --ith-stem phase_1000/phase_1000 "transformed scatterplot"
python3 plot-diffusion-map.py "AP(k=6000,eps=$e,points=6000,--no-normalize,start-time=2).diffmap" AP --ith-stem phase_1000/phase_1000 "eigenvalues"
python3 plot-diffusion-map.py "AP(k=6000,eps=$e,points=6000,--no-normalize,start-time=2).diffmap" AP --ith-stem phase_1000/phase_1000 "correlation plots"
